package org.springblade.common.security.exception;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import org.springblade.common.security.component.CsjAuth2ExceptionSerializer;
import org.springblade.core.tool.api.IResultCode;
import org.springblade.core.tool.api.ResultCode;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;

@JsonSerialize(using = CsjAuth2ExceptionSerializer.class)
public class CsjOAuth2Exception extends OAuth2Exception {
	@Getter
	private final IResultCode resultCode;

	public CsjOAuth2Exception(String msg) {
		super(msg);
		this.resultCode = ResultCode.FAILURE;
	}
	public CsjOAuth2Exception(IResultCode resultCode) {
		super(resultCode.getMessage());
		this.resultCode = resultCode;
	}

	public CsjOAuth2Exception(IResultCode resultCode, Throwable cause) {
		super(resultCode.getMessage(),cause);
		this.resultCode = resultCode;
	}

	/**
	 * 提高性能
	 *
	 * @return Throwable
	 */
	@Override
	public Throwable fillInStackTrace() {
		return this;
	}

	public Throwable doFillInStackTrace() {
		return super.fillInStackTrace();
	}
}
